<template>
	<view>
		<page-head :title="'授权手机号'" :headtype="2"></page-head>
		<view class="logo">
			<view  class="logomain marginAuto">
				<image src="@/static/logo.png" mode=""></image>
			</view>
		</view>
		<view class="sqbtn marginAuto" style="width:600rpx;margin-top:60rpx;">
			<uv-button text="授权手机号" openType="getPhoneNumber" @getphonenumber="getphonenumberfun" :customStyle="{
				'background':'#0089FB',
				'color':'#ffffff',
				'font-size':'30rpx',
				'width':'600rpx',
				'height':'100rpx',
				'border-radius':'100rpx'
			}"></uv-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				scene:'',
				type:'',
				openid:'',
				phone:''
			};
		},
		onLoad(parmas) {
			this.scene = parmas.scene || '';
			this.openid = parmas.openid || '';
			this.type = parmas.type || '';
		},
		methods: {
			getphonenumberfun(e){
				this.apifun.unirequest('/api/wx/getPhoneNumber','post',{
					code:e.code
				},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.phone = datas;
						this.wxloginfun();
					}else{
						this.apifun.toast(res.msg)
					}
				},true,true)
			},
			wxloginfun() {
				let sendData = {
					openid: this.openid || '',
					scene:this.scene || '',
					type:this.type || '',
					phone:this.phone || ''
				};
				this.apifun.unirequest('/api/wx/wxLogin', 'post', sendData, (res) => {
					if (res.code === 200) {
						let datas = res.data;
						this.token = datas.token;
						uni.setStorageSync('token', datas.token)
						this.apifun.goback();
					} else {
						this.apifun.toast(res.msg)
					}
				}, false,true)
			},
		},
	};
</script>

<style scoped lang="scss">
	.logo{
		padding: 150rpx 0 40rpx;
		.logomain{
			width:200rpx;
			height: 200rpx;
			image{
				width:200rpx;
				height: 200rpx;
				border-radius: 50%;
			}
		}
	}
	.sqbtn{
		position: fixed;
		left: 50%;
		bottom: 100rpx;
		width: 600rpx;
		margin-left: -300rpx;
	}
</style>